<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ page import="projects.milestone" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="createMilestone" class="projects.milestone"></jsp:useBean>
<jsp:setProperty property="*" name="createMilestone"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>

<%
if (request.getParameter("hProjectId") == null){
	response.sendRedirect("../General Info/dashboard.jsp");
	}
else  if (session.getAttribute("loggedIn") == null) {
	response.sendRedirect("../User/index.jsp");
	}
else{
%>

<body>
<%
	milestone mil = new milestone();
	mil.setProjectId(Integer.parseInt(request.getParameter("hProjectId")));
	mil.setMilestoneName(request.getParameter("milestoneName"));
	mil.setMilestoneDescription(request.getParameter("milestoneDesc"));
	mil.setStartDate(request.getParameter("startDate"));
	mil.setEndDate(request.getParameter("endDate"));
	mil.setMilestoneEffort(Double.parseDouble(request.getParameter("milestoneEffort")));
	mil.setMilestoneStateId(Integer.parseInt(request.getParameter("milestoneState")));
	mil.setMilestoneStateReason(request.getParameter("stateReason"));
	mil.setEstimatedCost(Double.parseDouble(request.getParameter("estimatedCost")));
	Integer milestoneId = mil.createMilestone();
	
	
	if ( milestoneId != 0){
		String milestoneLink = "../Milestones/milestone.jsp?id=" + milestoneId;
		session.setAttribute("postback", "true");
		session.setAttribute("createMilestone", "true");
		response.sendRedirect(milestoneLink);
	}
	else
	{
		String milestoneLink = "../Milestones/createNewTask.jsp?id=" + request.getParameter("id");
		session.setAttribute("postback", "true");
		session.setAttribute("createTask", "false");
		response.sendRedirect(milestoneLink);
	}
}
%>
</body>
</html>